<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" session="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
	</head>
	<body>
		<% if(request.getParameter("resetChat") != null)
			application.setAttribute("chatContent", null);
		
		%>
		<% String chatContent=(String)application.getAttribute("chatContent");
		    if (chatContent==null)
		    	chatContent="Bienvingut al xat!";
		    if(request.getParameter("nick") != null)
				 session.setAttribute("nickuser", request.getParameter("nick"));
		    if(request.getParameter("contenido") != null && session.getAttribute("nickuser") != null){
		    	chatContent= session.getAttribute("nickuser")+" "+"("+request.getRemoteAddr()+")"+ ": "+request.getParameter("contenido")+"<br>"+chatContent;
		    }
		    application.setAttribute("chatContent", chatContent);
		 
		 %>
		 
		 <p id="userchat"><%out.println(application.getAttribute("chatContent")); %></p>
		<form>
			Nick<input type="text" name="nick" value="<%if(session.getAttribute("nickuser") != null){out.print(session.getAttribute("nickuser"));} %>">
			Text<input type="text" name="contenido">
			<input type="submit" value="Submit">
			<input type="submit" value="Clear Chat" name="resetChat">
		</form>
	</body>
</html>